package mc

import (
	"gitee.com/dreamwood/ez-go/db/mgo"
)

const (
	NeedEventNew           = "erp.NeedNew"
	NeedEventBeforeCreate  = "erp.NeedBeforeCreate"
	NeedEventBeforeUpdate  = "erp.NeedBeforeUpdate"
	NeedEventBeforeSave    = "erp.NeedBeforeCreate erp.NeedBeforeUpdate"
	NeedEventAfterCreate   = "erp.NeedAfterCreate"
	NeedEventAfterUpdate   = "erp.NeedAfterUpdate"
	NeedEventAfterSave     = "erp.NeedAfterCreate erp.NeedAfterUpdate"
	NeedEventDelete        = "erp.NeedDelete"
	NeedAccessControlEvent = "erp.NeedAccessControl"
)

func GetNeedConfig() *mgo.DocConfig {
	return Need_Config
}

var Need_Config *mgo.DocConfig

func init() {
	Need_Config = NewNeedConfig()
}
func NewNeedConfig() *mgo.DocConfig {
	return &mgo.DocConfig{
		ContainerKey: "erp.Need",
		Fields: []string{
			"sn", "title", "status", "isClose", "formAt", "needAt", "formEmp", "createEmp", "needEmp", "needDept", "note", "product", "flow", "flowIndex", "flowName", "flowCur", "flows", "isConfirm", "confirmAt", "isCancel", "isLock", "approvalSate", "approvalStage",
		},
		RelationFields: []string{
			"status", "formEmp", "createEmp", "needEmp", "needDept", "product",
		},
		RelationConfigs: map[string]*mgo.DocRelation{
			"status": {
				Config:     GetNeedStatusConfig,
				DocName:    "NeedStatus",
				JoinType:   "O",
				KeyInside:  "statusId",
				KeyOutSide: "id",
			},
			"formEmp": {
				Config:     GetEmpConfig,
				DocName:    "Emp",
				JoinType:   "O",
				KeyInside:  "formEmpId",
				KeyOutSide: "id",
			},
			"createEmp": {
				Config:     GetEmpConfig,
				DocName:    "Emp",
				JoinType:   "O",
				KeyInside:  "createEmpId",
				KeyOutSide: "id",
			},
			"needEmp": {
				Config:     GetEmpConfig,
				DocName:    "Emp",
				JoinType:   "O",
				KeyInside:  "needEmpId",
				KeyOutSide: "id",
			},
			"needDept": {
				Config:     GetDepartmentConfig,
				DocName:    "Department",
				JoinType:   "O",
				KeyInside:  "needDeptId",
				KeyOutSide: "id",
			},
			"product": {
				Config:     GetNeedProductConfig,
				DocName:    "NeedProduct",
				JoinType:   "M",
				KeyInside:  "id",
				KeyOutSide: "belongToId",
			},
		},
		FieldFilter: map[string]*mgo.DocFieldFilter{
			"default": {
				Select: []string{},
				Omit:   []string{},
			},
		},
	}
}
